//
//  RootViewController.m
//  PlayerFix
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 DAT. All rights reserved.
//

#import "RootViewController.h"

#import "ClassifyViewController.h"
#import "ColumnViewController.h"

@interface RootViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIButton *oneButton;
@property (nonatomic, strong) UIButton *twoButton;
@property (nonatomic, strong) UIScrollView *bigScroView;
@property (nonatomic, strong) UILabel *aLabel;

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UILabel *bgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 375, 30)];
    [self.view addSubview:bgLabel];
    bgLabel.backgroundColor = RGBA(30, 80, 100, 1);
    //    bgLabel.userInteractionEnabled = YES;
    
    self.oneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.oneButton.frame = CGRectMake(100, 0, 50, 30);
    [self.oneButton setTitle:@"分类" forState:UIControlStateNormal];
    [self.oneButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [self.view addSubview:self.oneButton];
    [self.oneButton addTarget:self action:@selector(oneButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.aLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 28, 50, 2)];
    [self.view addSubview:self.aLabel];
    self.aLabel.backgroundColor = [UIColor greenColor];
    
    self.twoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.twoButton.frame = CGRectMake(220, 0, 50, 30);
    [self.twoButton setTitle:@"专题" forState:UIControlStateNormal];
    [self.twoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:self.twoButton];
    [self.twoButton addTarget:self action:@selector(twoButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.bigScroView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 30, 375, 667-64)];
    self.bigScroView.delegate = self;
    [self.bigScroView setBounces:NO];
    _bigScroView.scrollsToTop = NO;
    [self.bigScroView setPagingEnabled:YES];
    [self.view addSubview:self.bigScroView];
    self.bigScroView.contentSize = CGSizeMake(375 * 2, 667-94);
    
    // 分类
    ClassifyViewController *classifyVC = [[ClassifyViewController alloc] init];
    classifyVC.view.frame = CGRectMake(0, 0, 375, 667-64);
    [self.bigScroView addSubview:classifyVC.view];
    
    // 专题
    ColumnViewController *columnVC = [[ColumnViewController alloc] init];
    columnVC.view.frame = CGRectMake(375, 0, 375, 667-64);
    [self.bigScroView addSubview:columnVC.view];
    
}

// 滚动
// 滚动的时候被触发
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat x = scrollView.contentOffset.x / 375.0 * 120.0;
    self.aLabel.frame = CGRectMake(100 + x, 28, 50, 2);
}

// 减速停止
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (self.bigScroView.contentOffset.x / 375.0 == 0) {
        
        [self.oneButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [self.twoButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        self.aLabel.frame = CGRectMake(100, 28, 50, 2);
        
    }
    if (self.bigScroView.contentOffset.x / 375.0 == 1) {
        
        [self.oneButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [self.twoButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        self.aLabel.frame = CGRectMake(220, 28, 50, 2);
        
    }
}

- (void)oneButtonAction:(UIButton *)button{
    
    //    self.bigScroView.contentOffset = CGPointMake(0, 0);
    [self.bigScroView setContentOffset:CGPointMake(0, 0) animated:YES];
    [self.oneButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [self.twoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];}

- (void)twoButtonAction:(UIButton *)button{
    //    self.bigScroView.contentOffset = CGPointMake(375, 0);
    [self.bigScroView setContentOffset:CGPointMake(375, 0) animated:YES];
    [self.oneButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.twoButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
